import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import locale from "element-ui/lib/locale/lang/en"; // lang i18n

import "@/styles/index.scss"; // global css

import App from "./App";
import store from "./store";
import router from "./router";

import "@/icons"; // icon
import "@/permission"; // permission control
import { getToken } from "@/utils/auth"; // get token from cookie

import WujieVue from "wujie-vue2";
const { setupApp, bus } = WujieVue; //preloadApp

// qiankun 微应用
// import start from "@/qiankun";

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === "production") {
  const { mockXHR } = require("../mock");
  mockXHR();
}

Vue.use(WujieVue);

// set ElementUI lang to EN
Vue.use(ElementUI, { locale });
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});

setupApp({
  name: "react-app1",
  url: "//localhost:9098/",
  // exec: true,
  props: { getToken },
  fetch: (url, options) => {
    console.log("fetch", url, options);
    return window.fetch(url, { ...options, credentials: "omit" });
  },
  // plugins,
  // prefix: { "prefix-dialog": "/dialog", "prefix-location": "/location" },
  // degrade,
  // ...lifecycles,
});

// 在 xxx-sub 路由下子应用将激活路由同步给主应用，主应用跳转对应路由高亮菜单栏
bus.$on("sub-route-change", (name, path) => {
  const mainName = `${name}`;
  const mainPath = `/${name}${path}`;
  const currentName = router.currentRoute.name;
  const currentPath = router.currentRoute.path;
  if (mainPath !== currentPath) {
    router.push({ path: mainPath });
  }
});

// start({
//   sandbox: {
//     // strictStyleIsolation: true, // 开启严格的样式隔离模式
//     experimentalStyleIsolation: true, // 开启单实例场景子应用之间的样式隔离
//   },
//   // excludeAssetFilter: (a) => {
//   //   console.log(a, "excludeAssetFilterexcludeAssetFilter");
//   // },
// });
